package com.freecloud.javabasics.design.strategy;

import com.freecloud.common.LoggerUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: maomao
 * @Date: 2019-11-27 09:15
 */
public class StrategyContext {

    private static Map<String, Eat> register = new HashMap<>();
    static {
        register.put("chopstick",new Chopsticks());
        register.put("knife",new Knife());
        register.put("fork",new Fork());
    }


    public static void eat(String type){
        type = type.toLowerCase();
        if(!register.containsKey(type)){
            LoggerUtil.println("未知类型：%s",type);
            return;
        }
        register.get(type).eat();
    }
}

/**
 *  枚举方式策略
 */
class EnumStrategy{

    enum EatType{
        CHOPSTICK(new Chopsticks()),
        FORK(new Knife()),
        Knife(new Fork());

        private Eat eat;

        EatType(Eat eat){
            this.eat = eat;
        }
    }

    public static void eat(EatType type){
        type.eat.eat();
    }
}